﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.BizTalk.ExplorerOM;
using DBLOG.BizTalk.BizTalkExplorerServices.Core;

namespace DBLOG.BizTalk.BizTalkExplorerServices.Entities
{
    public class BTSReceivePort : BTSEntityBase
    {
        private ReceivePort _receivePort { get; set; }

        public List<BTSReceiveLocation> ReceiveLocations { get; set; }

        public BTSReceivePort()
        {
        }

        internal BTSReceivePort(ReceivePort receivePort)
        {
            this._receivePort = receivePort;

            this.PopulateSimpleProperties();

            this.PopulateReceiveLocations();
        }

        private void PopulateReceiveLocations()
        {
            var receiveLocations = from r in _receivePort.ReceiveLocations.Cast<ReceiveLocation>().ToList<ReceiveLocation>()
                                   select new BTSReceiveLocation(r);

            this.ReceiveLocations = receiveLocations.ToList<BTSReceiveLocation>();
        }

        private void PopulateSimpleProperties()
        {
            this.Name = _receivePort.Name;

            this.ApplicationName = _receivePort.Application.Name;
        }
    }
}
